import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
    public static void main(String[] args) throws IOException {
        LifeChess lifeChess = new LifeChess();
//        lifeChess.initializeBoard();
//        lifeChess.runGameOfLife();
        lifeChess.setSIZE(4);//设置棋盘大小
        //lifeChess.setLen(4);//设置棋盘大小
        lifeChess.setGENERATIONS(10);
        lifeChess.initializeBoardfromTxt("1.init.txt");//获取初始矩阵
        lifeChess.getRes("1.end.txt");//获取目标矩阵
        int [][] board = lifeChess.getBoard();
        ExecutorService lifeGame = Executors.newFixedThreadPool(8);
        for (int i = 0; i < lifeChess.getGENERATIONS(); i++) {
            board = lifeChess.getBoard();
//            if(lifeChess.checkRes()) {
//                lifeChess.printBoard(board);
//            }
            lifeChess.printBoard(board);
            for (int j = 0; j < lifeChess.getSIZE(); j++) {
                Thread_l thread = new Thread_l(lifeChess);
                thread.setSIZE(4);
                thread.setLINE(j);
                thread.setBoard(board);
                lifeGame.execute(thread);
            }
                lifeChess.printBoard(lifeChess.getBoard());
        }
    }
}
